from typing import Generic, TypeVar, Optional
from pydantic import BaseModel

T = TypeVar('T')

class ServerResponseEntity(BaseModel,Generic[T]):
  code:str
  msg:str
  data:Optional[T] = None

  @classmethod
  def success(cls,data:T, msg: str = "Success")-> "ServerResponseEntity[T]":
      return cls(code="200", msg=msg, data=data)


  @classmethod
  def error(cls, code: str = "500", msg: str = "Error", data: T = None) -> "ServerResponseEntity[T]":
    return cls(code=code, msg=msg, data=data)
